<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page">
      <template #table-handle-prepend="scope">
        <el-button size="mini" type="text" icon="el-icon-edit" @click="gotoDetail(scope.row.billNo)">查看</el-button>
      </template>

      <template #table-status="scope">
        <el-tag :type="scope.row.status === 'save'? 'info': (scope.row.status === 'audit'? 'success': 'danger')">{{ scope.row.status === 'save'? '保存': (scope.row.status === 'audit'? '审核': '关闭') }}</el-tag>
      </template>
      <template #table-taskStatus="scope">
        <el-tag :type="scope.row.taskStatus === 'save'? 'info': (scope.row.taskStatus === 'audit'? 'success': 'danger')">{{ scope.row.taskStatus === 'save'? '保存': (scope.row.taskStatus === 'audit'? '审核': '关闭') }}</el-tag>
      </template>
    </vb-page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false
    }
  },
  async mounted() {
    await this.getStock()
  },
  methods: {
    async getStock() {
      this.loading = true;
      try {
        let res = await this.$api.getChildDictionaryListByKeys({
          keys: ['stock']
        });
        if (!res.res) return;
        this.stockList = res.stock;
      } finally {
        this.loading = false;
      }
    },
    /**
     * 获取状态名
     */
    getStockName(val) {
      if (this.stockList && this.stockList.length > 0) {
        for(let i = 0; i < this.stockList.length; i++) {
          if (this.stockList[i].key === val) {
            return this.stockList[i].name;
          }
        }
      }
      return '';
    },
    gotoDetail(billNo = '') {
      let url = '/produce/materialBomDetail'
      if (billNo) {
        url += `?billNo=${ billNo }`
      }
      this.$router.push(url)
    },
  }
}
</script>

<style scoped>

</style>
